package com.butang.controller;

import com.butang.pojo.Emp;
import com.butang.pojo.PageBean;
import com.butang.pojo.Result;
import com.butang.service.EmpServiceImpl;
import com.butang.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

/**
 * ClassName: EmpController
 * Package: com.butang.controller
 * Description:
 *
 * @Author BuTang
 * @Create 2023/7/9 23:10
 * @Version 1.0
 */
@Slf4j
@RestController
public class EmpController {
    @Autowired
    private EmpServiceImpl empService;

    @GetMapping("/emps")
    public Result list(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize,
                       String name, Short gender,
                       @DateTimeFormat( pattern = "yyyy-MM-dd") LocalDateTime begin,
                       @DateTimeFormat( pattern = "yyyy-MM-dd") LocalDateTime end) {

        PageBean pageBeam = new PageBean();
        List<Emp> list = empService.list(page, pageSize, name,  gender,  begin, end);
        int count = empService.count();
        pageBeam.setRows(list);
        pageBeam.setTotal(count);
        return Result.success(pageBeam);
    }
    @DeleteMapping("/emps/{ids}")
    public Result empDelete(@PathVariable List<Integer> ids){
        empService.empDelete(ids);
        return Result.success();
    }

    @PostMapping("/emps")
    public Result add( @RequestBody Emp emp){

        empService.add(emp);
        return Result.success();
    }

    @GetMapping("/emps/{id}")
    public Result getEmp(@PathVariable Integer id ) {
        Emp emp = empService.getEmp(id);
        return Result.success(emp);
    }


        @PutMapping("/emps")
    public Result update(@RequestBody Emp emp){
        empService.update(emp);
        return Result.success();
    }


}
